home *** CD-ROM | disk | FTP | other *** search
- BaseProjectile = {
- tid_cloud = System:LoadTexture("textures/cloud.jpg"),
- decal_tid = System:LoadTexture("textures/decal/explo_decal.dds"),
-
- deleteOnGameReset=1,
-
- bPhysicalized = nil,
- was_underwater=nil,
-
- fDeformRadius = 3,
-
- SoundEvent = {
- fVolumeRadius = 200, -- default 13
- fThreat = 1, -- default 1
- fInterest = 0.0,
- },
- }
-
- function BaseProjectile:Server_OnInit()
- self.part_time = 0;
- if(self.bPhysicalized==nil)then
- self:CreateParticlePhys( 2, 10, 0 );
- self.bPhysicalized=1;
- end
-
- self.ExplosionParams = new(self.ExplosionParams);
-
- self:EnableUpdate(1);
-
- -- explode after a set amount of time
- self:SetTimer(self.lifetime);
-
- self:SetPos({x=-1000,y=-1000,z=-1000});
- end
-
- function BaseProjectile:Client_OnInit()
- self.part_time = 0;
- if(self.bPhysicalized==nil)then
- self:CreateParticlePhys( 2, 10 );
- self.bPhysicalized=1;
- end
- self:SetPhysicParams( PHYSICPARAM_PARTICLE, self.Param );
-
- self:EnableUpdate(1);
-
- self:SetViewDistRatio(255);
- self:LoadObject( self.projectileObject,0, self.projectileObjectScale);
- self:DrawObject( 0, 1 );
-
- local engineSound = self.EngineSound;
- if (engineSound) then
- engineSound.sound = Sound:Load3DSound(engineSound.name, 512);
- Sound:SetMinMaxDistance(engineSound.sound, engineSound.minDist, engineSound.maxDist);
- Sound:SetSoundLoop(engineSound.sound, 1);
- self:PlaySound(engineSound.sound);
- end
-
- -- Initialize Smoke trail particles.
- --if (self.SmokeEffect) then
- --self:CreateParticleEmitterEffect( 0,self.SmokeEffect,0,g_Vectors.v000,g_Vectors.v010,1 );
- --end
- end
-
- function BaseProjectile:Server_OnUpdate(dt)
- local status=GetParticleCollisionStatus(self);
- local pos=self:GetPos();
-
- if (status ~= nil and self.explodeOnContact == 1) then
- self.isExploding = 1;
- elseif (System:IsValidMapPos(pos) ~= 1) then
- self.isExploding = 1;
- end
-
- if (self.isExploding == 1) then
- self.ExplosionParams.pos = pos;
- Game:CreateExplosion( self.ExplosionParams );
-
- if (status == nil) then
- status = {};
- status.objtype = 0;
- end
-
- if (status.normal == nil) then
- status.normal = g_Vectors.v001;
- end
-
- -- spawn client side effect
- Server:BroadcastCommand("FX", self:GetPos(), status.normal, self.id, status.objtype); -- invoke OnServerCmd() on the client
-
- local soundEvent = self.SoundEvent;
- if (soundEvent ~= nil and self.ExplosionParams.shooter~=nil) then
- AI:SoundEvent(self.id, pos, soundEvent.fVolumeRadius, soundEvent.fThreat, soundEvent.fInterest, self.ExplosionParams.shooter.id);
- end
-
- self:KillTimer();
-
- Server:RemoveEntity(self.id);
- end
- end
-
- function BaseProjectile:Client_OnUpdate(dt)
- local pos = self:GetPos();
-
- if (self.Smoke) then
- self.part_time = self.part_time + dt*2;
- if (self.part_time>0.03) then
- Particle:CreateParticle(pos, g_Vectors.v000, self.Smoke);
- self.part_time=0;
- end
- end
-
- if (self.SmokeEffect) then
- local dir = self:GetDirectionVector();
- Particle:SpawnEffect( self:GetPos(),dir,self.SmokeEffect,1 );
- end
-
- if(Materials["mat_water"] and Materials["mat_water"].projectile_hit)then
- if(self.was_underwater==nil)then
- if(Game:IsPointInWater(pos)) then
- System:LogToConsole("UNDERWATER");
- self.was_underwater=1;
- ExecuteMaterial(pos, g_Vectors.v001, Materials.mat_water.projectile_hit, 1 )
- end
- end
- end
-
- -- vPos, fRadius, DiffR, DiffG, DiffB, DiffA, SpecR, SpecG, SpecB, SpecA, fLifeTime
- -- Commented out dynamic light for a framerate test - tig
- --self:AddDynamicLight(self:GetPos(), 10, 1, 1, 0.3, 1, 1, 1, 0.3, 1, 0);
- end
-
-
- function BaseProjectile:Launch( weapon, shooter, pos, angles, dir, target )
-
- -- register with the AI system
- if (self.Param.AI_Type) then
- if (self.Param.AI_Type == AIOBJECT_ATTRIBUTE) then
- AI:RegisterWithAI(self.id, AIOBJECT_ATTRIBUTE, shooter.id);
- else
- AI:RegisterWithAI(self.id, self.Param.AI_Type);
- end
- else
- AI:RegisterWithAI(self.id, AIAnchor.AIOBJECT_DAMAGEGRENADE);
- end
-
- -- special AI processing (for Mortar)
- if (shooter.ai and self.useAIProjectileShoot~=nil) then
- BaseProjectile.default_iv = self.Param.initial_velocity;
- self.Param.initial_velocity = AI:ProjectileShoot(shooter.id,self.Param);
- else
- self.Param.heading = dir;
- end
-
- self.Param.collider_to_ignore = shooter;
-
- self:SetPhysicParams( PHYSICPARAM_PARTICLE, self.Param );
-
- if (BaseProjectile.default_iv ~= nil) then
- self.Param.initial_velocity = BaseProjectile.default_iv;
- BaseProjectile.default_iv = nil;
- end
-
- --[kirill] start from some helper's position - for vehicle mounted RLs
- if( self.LaunchHelper ) then
- pos = shooter.cnt:GetTPVHelper(0, self.LaunchHelper);
- end
-
- self:SetViewDistRatio(255);
- self:SetPos( pos );
- self:SetAngles( angles );
- self.ExplosionParams.shooter = shooter;
- self.ExplosionParams.weapon = weapon;
- self.isExploding = nil;
-
- if (TargetLocker and shooter == _localplayer) then
- self.Target=TargetLocker:PopTarget();
- end
-
- -- the ID of the server slot who 'shot' this health pack
- -- used for statistics
- local serverSlot = Server:GetServerSlotByEntityId(shooter.id);
-
- --System:Log("BaseProjectile:Launch "..tostring(shooter.id));
-
- if (serverSlot) then
- self.shooterSSID = serverSlot:GetId();
- --System:Log("BaseProjectile:Launch b");
- end
- end
-
- function BaseProjectile:Client_OnRemoteEffect(toktable, pos, normal, userbyte)
- self:DrawObject(0,0);
-
- local hit = {};
- hit.pos = pos;
- hit.normal = normal;
- hit.target_material = Materials.mat_default;
- hit.play_mat_sound = 1;
- hit.objtype = userbyte;
-
- local effect = self.matEffect;
-
- --objtype 2 mean "the terrain"
- if (hit.objtype==2 and self.mark_terrain and (not self.was_underwater)) then
- if(not self.terrain_deformed)then
- self.terrain_deformed=1;
- System:DeformTerrain( pos, self.fDeformRadius, self.decal_tid, self.deform_terrain);
- -- in singleplayer we deform the terrain. We have to adjust the position where the
- -- particle system is spawned ... otherwise it looks like it is floating in the air
- if (self.deform_terrain and tonumber(s_deformable_terrain)==1) then
- hit.pos.z = hit.pos.z - 1;
- end
- end
- end
-
- if (self.EngineSound and self.EngineSound.sound) then
- Sound:StopSound(self.EngineSound.sound);
- end
-
- if(Game:IsPointInWater(hit.pos))then
- hit.target_material = Materials.mat_water;
- hit.normal = g_Vectors.v001;
- effect = "grenade_explosion";
- end
-
- ExecuteMaterial2(hit, effect);
-
- -- sound event for the radar
- local soundEvent = self.SoundEvent;
- if (soundEvent ~= nil) then
- Game:SoundEvent(hit.pos, soundEvent.fVolumeRadius, soundEvent.fThreat, 0);
- end
- end
-
- BaseProjectile.Server = {
- OnInit = BaseProjectile.Server_OnInit,
- OnTimer = function(self)
- self.isExploding = 1;
- end,
- OnUpdate = BaseProjectile.Server_OnUpdate,
- }
-
- BaseProjectile.Client = {
- OnInit = BaseProjectile.Client_OnInit,
-
- OnUpdate = BaseProjectile.Client_OnUpdate,
-
- OnRemoteEffect = BaseProjectile.Client_OnRemoteEffect,
- }
-
- function CreateProjectile(projectileDefinition)
- local ret=new(BaseProjectile);
-
- mergef(ret, projectileDefinition, 1);
-
- -- set some fallback default parameters
- if (ret.matEffect == nil) then
- ret.matEffect = "projectile_hit";
- end
- if (ret.matEffectScale == nil) then
- ret.matEffectScale = 1.0;
- end
-
- if (ret.projectileObject == nil) then
- ret.projectileObject = "objects/weapons/Rockets/rocket.cgf";
- end
-
- if (ret.projectileObjectScale == nil) then
- ret.projectileObjectScale = 0.5;
- end
-
- if (ret.lifetime == nil) then
- ret.lifetime = 30000;
- end
-
- return ret;
- end
-